﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
namespace Lawyer.Web.PostInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					string PostID= Request.Params["id"];
					ShowInfo(PostID);
				}
			}
		}
			
	private void ShowInfo(string PostID)
	{
		Lawyer.BLL.PostInfo bll=new Lawyer.BLL.PostInfo();
		Lawyer.Model.PostInfo model=bll.GetModel(PostID);
		this.lblPostID.Text=model.PostID;
		this.txtTile.Text=model.Tile;
		this.txtDetail.Text=model.Detail;
		this.txtStatus.Text=model.Status.ToString();
		this.txtCreatedBy.Text=model.CreatedBy;
		this.txtCreatedDate.Text=model.CreatedDate.ToString();
		this.txtUpdatedBy.Text=model.UpdatedBy;
		this.txtUpdatedDate.Text=model.UpdatedDate.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtTile.Text.Trim().Length==0)
			{
				strErr+="Tile不能为空！\\n";	
			}
			if(this.txtDetail.Text.Trim().Length==0)
			{
				strErr+="Detail不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtStatus.Text))
			{
				strErr+="Status格式错误！\\n";	
			}
			if(this.txtCreatedBy.Text.Trim().Length==0)
			{
				strErr+="CreatedBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreatedDate.Text))
			{
				strErr+="CreatedDate格式错误！\\n";	
			}
			if(this.txtUpdatedBy.Text.Trim().Length==0)
			{
				strErr+="UpdatedBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtUpdatedDate.Text))
			{
				strErr+="UpdatedDate格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string PostID=this.lblPostID.Text;
			string Tile=this.txtTile.Text;
			string Detail=this.txtDetail.Text;
			int Status=int.Parse(this.txtStatus.Text);
			string CreatedBy=this.txtCreatedBy.Text;
			DateTime CreatedDate=DateTime.Parse(this.txtCreatedDate.Text);
			string UpdatedBy=this.txtUpdatedBy.Text;
			DateTime UpdatedDate=DateTime.Parse(this.txtUpdatedDate.Text);


			Lawyer.Model.PostInfo model=new Lawyer.Model.PostInfo();
			model.PostID=PostID;
			model.Tile=Tile;
			model.Detail=Detail;
			model.Status=Status;
			model.CreatedBy=CreatedBy;
			model.CreatedDate=CreatedDate;
			model.UpdatedBy=UpdatedBy;
			model.UpdatedDate=UpdatedDate;

			Lawyer.BLL.PostInfo bll=new Lawyer.BLL.PostInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
